package com.tmpt.controller.springmvc.handlers;

import com.tmpt.dto.Result;
import com.tmpt.utils.StringUtils;
import com.tmptSource.dto.*;
import com.tmptSource.service.intf.*;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wxy on 2017/10/17.
 */

@Controller
@RequestMapping("/springmvc/owHWAction")
public class OwHWAction {

    private Logger log = Logger.getLogger(this.getClass());

    @Resource
    private IOw4HWService ow4HWService;


    /**
     * 查看个人资料
     * @return
     */
    @RequestMapping(value = "/pageUserList")
    @ResponseBody
    public Result pageUserList(HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<A2userDto> result = new Result();
        try {
            PageDto pageDto = new PageDto();
            pageDto.setPageSize(1000000000);
            pageDto.setPageCurrent(0);
            pageDto.setPageIndex(0);
            pageDto.setSortColumn("id");
            pageDto.setSortOrder("desc");

            //验证用户账号与密码是否对应
            result = ow4HWService.paginationUser(new A2userDto(), pageDto);
            if(!result.isSuccess()){
                return result;
            }
            List rows = new ArrayList();
            for(A2userDto a2userDto: (List<A2userDto>)result.getResultMap().get("rows")){
                a2userDto.setAppPassword("");
                a2userDto.setPassword("");
                a2userDto.setLoginname("");
                a2userDto.setAppLoginname("");
                a2userDto.setLogintimelast("");
                a2userDto.setLogintimes("");
                a2userDto.setCreatedate("");
                a2userDto.setCreateman("");
                a2userDto.setModifyman("");
                a2userDto.setModifymanId("");
                a2userDto.setCreatemanId("");
                a2userDto.setModifydate("");
                a2userDto.setClientID("");
                rows.add(a2userDto);
            }
            result.getResultMap().put("rows",rows);


            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
            //System.out.println("loginApp final："+result.getContent());
        }
    }

    @RequestMapping(value = "/pageTrackList")
    @ResponseBody
    public Result pageTrackList(OwUserTrackDto owUserTrackDto, String sortOrder,  HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwUserTrackDto> result = new Result();
        try {
            //查询参数
            PageDto pageDto = new PageDto();
            pageDto.setPageSize(1000000000);
            pageDto.setPageCurrent(0);
            pageDto.setPageIndex(0);
            pageDto.setSortColumn("id");
            pageDto.setSortOrder("desc");
            if(!StringUtils.isNull(sortOrder)) {
                pageDto.setSortOrder(sortOrder);
            }
            //调用远程服务
            Result<OwUserTrackDto> result1 =  ow4HWService.paginationTrack(owUserTrackDto, pageDto);
            if(!result1.isSuccess()){
                return result1;
            }
            List<Map<String,String>> rowsList = new ArrayList<Map<String, String>>();
            Map<String,String> map = null;
            for(OwUserTrackDto owUserTrackDto1: (List<OwUserTrackDto>)result1.getResultMap().get("rows")){
                map = new HashMap<String, String>();
                map.put("lat",owUserTrackDto1.getLat());
                map.put("lng",owUserTrackDto1.getLng());
                map.put("a2userId",owUserTrackDto1.getA2userId());
                map.put("createdate",owUserTrackDto1.getCreatedate());
                map.put("id",owUserTrackDto1.getId());
                rowsList.add(map);
            }
            result.getResultMap().put("rows",rowsList);

            return result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
            //System.out.println("final+"+result.getContent());
        }
    }






}